package  
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	/**
	 * ...
	 * @author DarkGoodWIN
	 */
	
	public class TModalMessage extends TModalWindow
	{		
		private var R: Trect;
		private var Text: Ttext;
		
		public override function Close(): void
		{
			super.Close();
			TModalWindow.Parent.Ctrl.removeChild(R.Ctrl);			
		}
		
		private function OnBtnClick(e: MouseEvent): void
		{
			Close();
		}
		
		private function ArrangeString(): void
		{
			Text.Height = 200;
			Text.Width = R.Width;
			Text.X = 0;
			Text.Y = 60 - (Text.text_field.numLines * Text.text_field.textHeight / 2);
		}
		
		private var Btns: Array = null;
		private static var _height : int = 200;
		private static var _width : int = 300;
		
		private function ArrangeButtons(): void
		{
			var BtnsWidth: int = -10;
			for ( var i: int = 0; i < Btns.length; ++i )
				BtnsWidth += Btns[i].Width + 10;
			var LastX: int = (R.Width / 2) - (BtnsWidth / 2);
			for ( var j: int = 0; j < Btns.length; ++j )
			{
				Btns[j].X = LastX;
				LastX += Btns[j].Width + 10;
				Btns[j].Y = _height - 80;			
			}
		}
		
		public function AddBtn(Caption: String, OnClick: Function, DoClose: Boolean = false): void
		{
			var Btn: InvControl = new InvControl(TKNRes.ok_btn, R, 0, 0);
			Btns[Btns.length] = Btn;
			Btn.Width = 100;
			Btn.Height = 50;
			var Text: Ttext = new Ttext(Caption, Btn, 10, 10);
			Text.X = (Btn.Width - Text.Width) / 2;
			Text.Height = 35;
			Btn.addEventListener(MouseEvent.CLICK, OnClick);			
			if (DoClose)
				Btn.addEventListener(MouseEvent.CLICK, OnBtnClick);
			ArrangeButtons();
		}
		
		public function AddCloseBtn(Caption: String): void
		{
			AddBtn(Caption, OnBtnClick);			
		}

		public function TModalMessage(text: String, WithCloseBtn: Boolean = true, CloseCaption: String = "Яяясно"): void 
		{
			super();
			var _x : int = 250;
			var _y : int = 200;

			R = new Trect(TModalWindow.Parent, 0xFFDDBB, _x, _y, _width, _height, true);
			
			Text = new Ttext('', R, 0, 0, false);
			Text.text_field.multiline = true;
			Text.text_field.htmlText = '<P ALIGN="center">' + text + '</P>';
			ArrangeString();

			Btns = new Array();
			if (WithCloseBtn)
				AddCloseBtn(CloseCaption);
		}
		
	}

}